package com.oocl.produce.producer;

import java.util.List;

import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.Message;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;

import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.command.ActiveMQQueue;


public class ProducerPtp {

	public static void produce(List<String> list) throws Exception{
		ConnectionFactory factory=new ActiveMQConnectionFactory("tcp://127.0.0.1:61616");
		Destination queue=new ActiveMQQueue("wyatt");
		Connection con=factory.createConnection();
		con.start();
		Session sen=con.createSession(true, Session.CLIENT_ACKNOWLEDGE);
		MessageProducer producer=sen.createProducer(queue);
		for (int i=0;i<list.size();i++) {
			TextMessage msg=sen.createTextMessage(list.get(i));
			producer.send(msg);
			sen.commit();
		}
		producer.close();
		sen.close();
		con.close();
	}

}
